package com.atguigu4.dao;

import com.beans.Order;

import java.sql.Connection;
import java.util.List;

/**
 * @auther user
 * @date 2021/12/10 - 6:29
 */
public class OrderDaoImpl extends BaseDao<Order> implements OrderDao {
    @Override
    public int inert(Connection connection, Order order) {
        String sql = "insert into `order`(order_name,order_date) values(?,?)";
        return update(connection,sql,order.getOrderName(),order.getOrderDate());
    }

    @Override
    public int deleteById(Connection connection, int id) {
        String sql = "delete from `order` where order_id = ?";
        return update(connection,sql,id);
    }

    @Override
    public int updateById(Connection connection, Order order) {
        String sql = "update `order` set order_name = ?,order_date = ? where order_id = ?";
        return update(connection,sql,order.getOrderName(),order.getOrderDate(),order.getOrderId());
    }

    @Override
    public Order getOrderById(Connection connection, int id) {
        String sql = "select order_id as orderId,order_name as orderName,order_date as orderDate from `order` where order_id = ?";
        Order order = getInstance(connection, sql, id);
        return order;
    }

    @Override
    public List<Order> getAll(Connection connection) {
        String sql = "select order_id as orderId,order_name as orderName,order_date as orderDate from `order`";
        List<Order> orderList = getForList(connection, sql);
        return orderList;
    }

    @Override
    public Long getCount(Connection connection) {
        String sql = "select count(*) from `order`";
        Long count = getValue(connection, sql);
        return count;
    }
}
